<?php

/**
 * oRs
 *
 * @version 3.0
 * @copyright 2009 Ron Planken
 * @class: utilities
 * @description: Handles all utilitie calls
 */

class utilities
{
				private $_start_time;
				private $_stop_time;
	
				public $timerDuration;
				public $roundTo = 4;
				
				//Start to log the time
        public function startTimer() {
            $microstart = explode(' ',microtime());
            $this->_start_time = $microstart[0] + $microstart[1];
        }
        
			  //end the time log
        public function stopTimer() {
            $microstop = explode(' ',microtime());
            $this->_stop_time = $microstop[0] + $microstop[1];
        }
        
				//count the time
        public function calculateTimer() {
            $this->timerDuration = round($this->_stop_time - $this->_start_time,$this->roundTo);
            return $this->timerDuration; 
        }

			  public function debug_array($array) {
					if ( $_DEBUG && ($_SESSION['level'] == 4)) {
					echo "<pre>";
					print_r($array);
					echo "</pre>";
					}
				}
				
				function create_salt($nc, $a='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') {
				   $l=strlen($a)-1; $r='';
				   while($nc-->0) $r.=$a{mt_rand(0,$l)};
				   return $r;
				}
				
				function check_email_adress($email) {
				  $result = TRUE;
				  if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) {
				    $result = FALSE;
				  }
				  return $result;
				}
				function debug_print($debug_info, $time = 0) {
				
					global $_DEBUG;
					global $_DEBUG_INFO;
					global $_QUERY_AMMOUNT;
					
					if ( $_DEBUG && ($_SESSION['level'] == 4)) {
				
						$info .= 'Time: ' . $time . '<br>' . $debug_info;
					
					}
					
					$_QUERY_AMMOUNT = $_QUERY_AMMOUNT + 1;
					
					$_DEBUG_INFO .= "<br>" . $info;
					
				}

}